//方法一：暴力查找
int search(int* nums, int numsSize, int target) {
    for(int i = 0; i < numsSize; i++){
        if(nums[i] == target)
            return i;
        if(nums[i] > target)
            return -1;
    }
    return -1;
}

//方法二：二分查找
int search(int* nums, int numsSize, int target) {
    int left = 0, right = numsSize - 1;
    
    while(left <= right){
        int mid = left + (right - left)/2;
        if(nums[mid] < target){
            left = mid + 1;
        }      
        else if(nums[mid] > target){
            right = mid - 1;
        } 
        else{
            return mid;
        }
    }
    return -1;
}

/*给定一个n个元素有序的（升序）整型数组nums和一个目标值target，

写一个函数搜索nums中的target，如果目标值存在返回下标，否则返回-1。*/